//
//  AppCoordinator.swift
//  CitySearch
//
//  Created by guotonglin on 2020/6/2.
//  Copyright © 2020 guotonglin. All rights reserved.
//

import Foundation
import UIKit

class AppCoordinator: BaseCoordinator {
    
    let window: UIWindow
    
    private let navigationController: UINavigationController =  {
        let navigationController = UINavigationController()
        let navigationBar = navigationController.navigationBar
        navigationBar.setBackgroundImage(UIImage(), for: .default)
        navigationBar.shadowImage = UIImage()
        navigationBar.barTintColor = UIColor(red: 233.0/255.0, green: 55.0/255.0, blue: 72.0/255.0, alpha: 1.0)
        navigationBar.tintColor = .white
        navigationBar.titleTextAttributes = [
            NSAttributedString.Key.font : UIFont(name: "Avenir-Medium", size: 28.0)!,
            NSAttributedString.Key.foregroundColor: UIColor.white
        ]
        navigationBar.isTranslucent = false
        return navigationController
    }()
    
    init(window: UIWindow) {
        self.window = window
    }
    
    override func start() {
        // 加载 SearchCity 模块
        
        let router = Router(navigateionConroller: self.navigationController)
        let searchCityCoordinator = SearchCityCoordinator(router: router)
        self.add(coordinator: searchCityCoordinator)
        searchCityCoordinator.isCompleted = { [weak self, weak searchCityCoordinator] in
            guard let `self` = self, let searchCityCoordinator = searchCityCoordinator else {
                return
            }
            self.remove(coordinator: searchCityCoordinator)
        }
        searchCityCoordinator.start()
        self.window.rootViewController = navigationController
        self.window.makeKeyAndVisible()
    }
    
}
